$(function () {
    // 获取消费记录
    var loading = weui.loading('loading', {
        className: 'custom-classname'
    });
    var result = Model.user.findUserByUserid({
        userid: sessionStorage.getItem("xt_userid")

    });
    var report = Model.user.findBillByUseridForPage();

    $('.balance-num').text(result.loginedUser.balance);
    for (var i = 0; i < report.bills.length; i++) {
        var item = '<div class="weui-cells shop-item"><div class="weui-cell"><div class="weui-cell__bd"><p>';
        switch (report.bills[i].state) {
            case 0: {
                item += '充值' + '</p><p class="report-time">';
                item += report.bills[i].createtime + '</p></div><div class="weui-cell__ft"><h2>+' + report.bills[i].price + '</h2></div></div></div>'

                break;
            }
            case 1: {
                item += '做买卖' + '</p><p class="report-time">';
                item += report.bills[i].createtime + '</p></div><div class="weui-cell__ft"><h2>' + report.bills[i].price + '</h2></div></div></div>'

                break;
            }
            case 2: {
                item += '提现' + '</p><p class="report-time">';
                item += report.bills[i].createtime + '</p></div><div class="weui-cell__ft"><h2>-' + report.bills[i].price + '</h2></div></div></div>'

                break;
            }
        }
        $('.shop-items').append(item);
    }
    loading.hide();
});

// 提现按钮
$(document).on('click', '.withdraw-btn', function () {
    // 判断金额是否大于0
    if (parseInt($('.balance-num').text()) <= 0) {
        weui.alert('余额不足，无法提现');
        return false;
    }
    location.href = 'encash.html';
});